package com.cg.design.graphicdesignpattern.observer;

/**
 * 表示数值递增的类，是NumberGenerator的子类
 *
 * @program: LeetCode->IncrementalNumberGenerator
 * @description: 表示数值递增的类，是NumberGenerator的子类
 * @author: cg
 * @create: 2022-03-29 21:56
 **/
public class IncrementalNumberGenerator extends NumberGenerator {

    /**
     * 当前数值
     */
    private int number;
    /**
     * 结束数值（不包含该值）
     */
    private final int end;
    /**
     * 递增步长
     */
    private final int stepSize;

    public IncrementalNumberGenerator(int number, int end, int stepSize) {
        this.number = number;
        this.end = end;
        this.stepSize = stepSize;
    }

    @Override
    public int getNumber() {
        return number;
    }

    @Override
    public void execute() {
        while (number < end) {
            notifyObserves();
            number += stepSize;
        }
    }
}
